# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=twisted
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=24.11.0
pkgrel=1
pkgdesc='An asynchronous networking framework written in Python (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-twisted'
  'purl: pkg:pypi/twisted'
  "cpe: cpe:/a:twistedmatrix:twisted"
)
msys2_repository_url='https://github.com/twisted/twisted/'
msys2_changelog_url='https://github.com/twisted/twisted/blob/HEAD/NEWS.rst'
msys2_documentation_url='https://docs.twisted.org/'
url='https://twisted.org/'
license=('spdx:MIT')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-attrs
    ${MINGW_PACKAGE_PREFIX}-python-automat
    ${MINGW_PACKAGE_PREFIX}-python-constantly
    ${MINGW_PACKAGE_PREFIX}-python-hyperlink
    ${MINGW_PACKAGE_PREFIX}-python-incremental
    ${MINGW_PACKAGE_PREFIX}-python-twisted_iocpsupport
    ${MINGW_PACKAGE_PREFIX}-python-typing_extensions
    ${MINGW_PACKAGE_PREFIX}-python-zope.interface
)
makedepends=(${MINGW_PACKAGE_PREFIX}-python-build
             ${MINGW_PACKAGE_PREFIX}-python-installer
             ${MINGW_PACKAGE_PREFIX}-python-hatchling
             ${MINGW_PACKAGE_PREFIX}-python-hatch-fancy-pypi-readme)
options=(!strip)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('695d0556d5ec579dcc464d2856b634880ed1319f45b10d19043f2b57eb0115b5')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
